<?

$_throwout = "/".$CONTEXT['lang_prefix']."claim/show-sent/";

if (gccLoggedIn()) {
			
	header("Location: $_throwout\n");
	exit;
}

if (isset($_POST['vlogin'])) {		// if trying to login

//dbdebug(1,1);

	if ($login = str_safe(trim(postdata('login')))) {		// something entered
//debug($login);
		$pass = str_safe(trim(postdata('pass')));
//debug($pass);

		if ($vuser = datafetch('db_item', 'cs_person', "email='$login' AND pass='".pwd($pass, $login)."'")) {

			if ($vuser['auth_id'] && $user = datafetch('db_item', tb('auth'), "id=$vuser[auth_id]")) {
	
				$user['time'] = date("H:i");
				
				$user['vuser'] = array_merge(gccLoadPerson($vuser['person_id']), $vuser);	// load person data
//debug($user, 'user', 1);				
				$user['settings'] = json_decode($user['settings'], true);
				if (!is_array($user['settings'])) $user['settings'] = array();
//debug($user);
				create_session($user);
			}
	
		} else {
	
			$DATA['login_error'] = "Невірний логін або пароль";
			// some diags for bad user/password
		}
			
	} else {
		$DATA['login_error'] = "Логін не введено";
	}

	if (!$DATA['login_error']) {
		header("Location: $_throwout\n");
		exit;
	}
}

unstack();